<?php
/**
 *
 * @author crystal
 * @version 
 */
require_once 'Zend/View/Interface.php';

/**
 * BlockNews helper
 *
 * @uses viewHelper Zend_View_Helper
 */
class Zend_View_Helper_PriceSystemElement {
	
	/**
	 * @var Zend_View_Interface 
	 */
	public $view;
	
	/**
	 * 
	 */
	public function priceSystemElement($priceSystem, $role = null) {
       
        $reg = Zend_Registry::getInstance();
        
        $colNameStyle = "";
        $colNameStyle .= "background-color: #" . $priceSystem['system_color'];
        if (isset($priceSystem['file_name'])){
            $colNameStyle .= ";background-image: url('" . $this->view->baseUrl(Application_Model_IconService::getInstance()->getIconPath("system_textures", $priceSystem['file_name'], array('y' =>200))) . "')";
        }
        
		$priceRow = "";
		$priceRow .= "<tr>";
            $priceRow .= "<td class='color' style =\"" . $colNameStyle . "\" rowspan='" . ($reg->acl->isAllowed($role, 'show_costs') ? 2 : 1) . "'>";
                if ($priceSystem['name'] != null){
        			$priceRow .= $priceSystem['name'];
        		} else {
      		        $priceRow .= "No name !";
        		}
            $priceRow .= "</td>";
            
            $priceRow .= "<td>";
                $priceRow .= "Вартість";
            $priceRow .= "</td>";
            
            $priceRow .= "<td>";
                $priceRow .= $priceSystem['price_cornice'] ;
            $priceRow .= "</td>";
            
            $priceRow .= "<td>";
                $priceRow .= $priceSystem['price_threshold'];
            $priceRow .= "</td>";
            
            $priceRow .= "<td>";
                $priceRow .= $priceSystem['price_top_bar'];
            $priceRow .= "</td>";
            
            $priceRow .= "<td>";
                $priceRow .= $priceSystem['price_bottom_bar'];
            $priceRow .= "</td>";
            
            $priceRow .= "<td>";
                $priceRow .= $priceSystem['price_separator'];
            $priceRow .= "</td>";
            
            $bottomData = "";
    		if ($reg->acl->isAllowed($role, 'remove_system')){
    			$bottomData .= "<div class='button'><a href='" .
    						$this->view->url( array('controller' => 'materials', 'action' => 'delsystem', 'id' => $priceSystem['id'])) .
    						"'>Видалити</a></div>";
            }
    		if ($reg->acl->isAllowed($role, 'edit_system')){
                $bottomData .= "<div class='button'><a href='" .
    						$this->view->url( array('controller' => 'materials', 'action' => 'editsystem', 'id' => $priceSystem['id'])) .
    						"'>Редагувати</a></div>";
    		}
    		
            
            $priceRow .= "<td rowspan='" . ($reg->acl->isAllowed($role, 'show_costs') ? 2 : 1) . "'>";
                if ($bottomData != ""){
        			$priceRow .= $bottomData;
        		}
            $priceRow .= "</td>";
            
        $priceRow .= "</tr>";
        
        $costsRow = "";
        $costsRow .= "<tr>";
        if ($reg->acl->isAllowed($role, 'show_costs')){
            $costsRow .= "<td>";
                $costsRow .= "Собівартість";
            $costsRow .= "</td>";
            
            $costsRow .= "<td>";
                $costsRow .= $priceSystem['cost_cornice'];
            $costsRow .= "</td>";
            
            $costsRow .= "<td>";
                $costsRow .= $priceSystem['cost_threshold'];
            $costsRow .= "</td>";
            
            $costsRow .= "<td>";
                $costsRow .= $priceSystem['cost_top_bar'];
            $costsRow .= "</td>";
            
            $costsRow .= "<td>";
                $costsRow .= $priceSystem['cost_bottom_bar'];
            $costsRow .= "</td>";
            
            $costsRow .= "<td>";
                $costsRow .= $priceSystem['cost_separator'];
            $costsRow .= "</td>";
        }
        $costsRow .= "</tr>";
        
		return $priceRow . $costsRow;
	}
	
	/**
	 * Sets the view field 
	 * @param $view Zend_View_Interface
	 */
	public function setView(Zend_View_Interface $view) {
		$this->view = $view;
	}
}

